using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Mvc.Ajax;
using HyperLocal.Core;
using HyperLocal.Service;

namespace HyperLocal.MVC.Controllers
{
    public class AlbumController : Controller
    {
        #region Controller Methods

        //
        // GET: /Album/
        [Authorize]
        public ActionResult Index()
        {
            Repository repo = ConnectionService.getRepository;
            var user = repo.First<LocalOrbUser>(x => x.UserName == User.Identity.Name);
            return View(user.LocalOrbAlbums);
        }

        //
        // GET: /Album/Details/5
        [Authorize]
        public ActionResult Details(Guid id)
        {
            Repository repo = ConnectionService.getRepository;
            var Album = repo.First<LocalOrbAlbum>(x => x.LocalOrbAlbumId == id);
            return View(Album);
        }

        //
        // GET: /Album/Create
        [Authorize]
        public ActionResult Create()
        {
            return View();
        }

        //
        // POST: /Album/Create
        [Authorize]
        [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult Create(FormCollection collection)
        {
            try
            {
                // TODO: Add insert logic here

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }

        //
        // GET: /Album/Edit/5

        public ActionResult Edit(Guid id)
        {
            Repository repo = ConnectionService.getRepository;
            var Album = repo.First<LocalOrbAlbum>(x => x.LocalOrbAlbumId == id);
            return View(Album);
        }

        //
        // POST: /Album/Edit/5
        [Authorize]
        [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult Edit(Guid id, FormCollection collection)
        {
            Repository repo = ConnectionService.getRepository;
            var Album = repo.First<LocalOrbAlbum>(x => x.LocalOrbAlbumId == id);

            try
            {
                // TODO: Add update logic here

                return RedirectToAction("Index");
            }
            catch
            {
                return View(Album);
            }
        } 

        #endregion
    }
}
